# encoding: utf-8
# Model for handling WMS/WFS query proxying
class Map < ActiveRecord::Base

  # Proxies WMS GET query to NLS API
  #
  # * *Args*    :
  #   - +user+ -> API username
  #   - +pass+ -> API password
  #   - +query+ -> GET query string
  # * *Returns* :
  #   - HTTP response from NLS API
  #
  def self.wmsGet(user, pass, query)
    auth = {:username => user, :password => pass}
    res = HTTParty.get('https://ws.nls.fi/rasteriaineistot/image?'+query, :basic_auth => auth)
  end
  
  # Proxies WMS POST query to NLS API
  #
  # * *Args*    :
  #   - +user+ -> API username
  #   - +pass+ -> API password
  #   - +post_data+ -> POST data to be submitted
  # * *Returns* :
  #   - HTTP response from NLS API
  #
  def self.wmsPost(user, pass, post_data)
    auth = { :username => user, :password => pass }
    options = { :body => post_data, :basic_auth => auth }
    res = HTTParty.post('https://ws.nls.fi/rasteriaineistot/image?', options)
  end
  
  # Proxies WFS GET query to NLS API
  #
  # * *Args*    :
  #   - +user+ -> API username
  #   - +pass+ -> API password
  #   - +query+ -> GET query string
  # * *Returns* :
  #   - HTTP response from NLS API
  #
  def self.wfsGet(user, pass, query)
    auth = {:username => user, :password => pass}
    res = HTTParty.get('https://ws.nls.fi/nimisto/wfs?'+query, :basic_auth => auth)
  end
  
  # Proxies WFS POST query to NLS API
  #
  # * *Args*    :
  #   - +user+ -> API username
  #   - +pass+ -> API password
  #   - +post_data+ -> POST data to be submitted
  # * *Returns* :
  #   - HTTP response from NLS API
  #
  def self.wfsPost(user, pass, post_data)
    auth = { :username => user, :password => pass }
    options = { :body => post_data, :basic_auth => auth }
    res = HTTParty.post('https://ws.nls.fi/nimisto/wfs?', options)
  end
end
